#include "myplane.h"
#include "base.h"
#include"bullet.h"
#include<QRect>
HeroPlane::HeroPlane()
{
    //初始化加载飞机图片资源
        m_Plane.load(HERO_PATH);
        m_Planepro.load(HERO_PATH1);
        //初始化坐标
        m_X = GAME_WIDTH * 0.5 - m_Plane.width()*0.5;
        m_Y = GAME_HEIGHT - m_Plane.height();
       //初始化矩形框
        m_Rect.setWidth(m_Plane.width());
        m_Rect.setHeight(m_Plane.height());
        m_Rect.moveTo(m_X,m_Y);
        m_recorder=0;
        bullet_interval=BULLET_INTERVAL;
        Shields=SHIELDS;
        Shields_max=SHIELDS;
}
void HeroPlane::setPosition(int x, int y)
{
    m_X = x;
    m_Y = y;
    m_Rect.moveTo(m_X,m_Y);
}
void HeroPlane::shoot()
{
    //累加时间间隔记录变量
    m_recorder++;
    //判断如果记录数字 未达到发射间隔，直接return
    if(m_recorder < bullet_interval)
    {
        return;
    }
    //到达发射时间处理
    //重置发射时间间隔记录
    m_recorder = 0;

    //发射子弹
    for(int i = 0 ; i < BULLET_NUM;i++)
    {
        //如果是空闲的子弹进行发射
        if(m_bullets[i].bullet_Free)
        {
            //将改子弹空闲状态改为假
            m_bullets[i].bullet_Free = false;
            //设置发射的子弹坐标
            m_bullets[i].bullet_X = m_X + m_Rect.width()*0.5 - 10;
            m_bullets[i].bullet_Y = m_Y - 25 ;
            break;
        }
    }
}
bool HeroPlane::Underprotecttime()
{
    protectrecoder++;
    if(protectrecoder>=300)
    {
        return false;
    }
    else
        return true;
}
